package com.situ.day6;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.junit.Test;

public class ArrayListDemo {
	
	public static void main(String[] args) {
		System.out.println("ArrayListDemo.main()");
	}
	
	@Test
	public void test1() {
		Student[] students = new Student[3];
		Student student1 = new Student(1, "zhansgan1", 20);
		Student student2 = new Student(2, "zhansgan2", 20);
		Student student3 = new Student(3, "zhansgan3", 20);
		students[0] = student1;
		students[1] = student2;
		students[2] = student3;
		for (int i = 0; i < students.length; i++) {
			System.out.println(students[i]);
		}
		System.out.println("-----------");
		//<Student>代表ArrayList里面只能放Student
		ArrayList<Student> list = new ArrayList<>();
		list.add(student1);
		list.add(student2);
		list.add(student3);
		//list.add("Hello");
		ArrayList list2 = new ArrayList();
		list2.add(student1);
		list2.add(1);
		list2.add("hello");
		//1、数组方式遍历
		for (int i = 0; i < list.size(); i++) {
			Student student = list.get(i);
			System.out.println(student);
		}
		for (int i = 0; i < list2.size(); i++) {
			Object object = list2.get(i);
		}
		System.out.println("------------");
		//2、foreach
		for (Student student : list) {
			System.out.println(student);
		}
		for (Object object : list2) {
			System.out.println(object);
		}
	}
	
	@Test
	public void test2() {
		//List<Student> list = new ArrayList<>();
		ArrayList<Student> list = new ArrayList<>();
		Student student1 = new Student(1, "zhansgan1", 20, "Java");
		Student student2 = new Student(2, "zhansgan2", 20, "Java");
		Student student3 = new Student(3, "zhansgan3", 20, "Java");
		list.add(student1);
		list.add(student2);
		list.add(student3);
		list.add(student3);
		list.add(student3);
		System.out.println(list.size());//5
		for (Student student : list) {
			System.out.println(student);
		}
		System.out.println("----------------");
		//Set<Student> set = new HashSet<>();
		HashSet<Student> set = new HashSet<>();
		set.add(student1);
		set.add(student2);
		set.add(student3);
		set.add(student3);
		set.add(student3);
		System.out.println(set.size());//3
		for (Student student : set) {
			System.out.println(student);
		}
	}
	
	@Test
	public void test44() {
		//Map<String, String> map = new HashMap<>();
		HashMap<String, String> map = new HashMap<>();
		map.put("CN", "中华人民共和国");
		map.put("US", "美利坚合众国");
		//根据key，找到这个key对应的这个值value
		String value1 = map.get("CN");
		System.out.println(value1);//中华人民共和国
		String value2 = map.get("US");
		System.out.println(value2);
		// Map遍历
		Set<Entry<String, String>> set = map.entrySet();
		for (Entry<String, String> entry : set) {
			String key = entry.getKey();
			String value = entry.getValue();
			System.out.println("key:" + key);
			System.out.println("value:" + value);
		}
		System.out.println("---------------");
		Set<String> keySet = map.keySet();
		for (String key : keySet) {
			String value = map.get(key);
			System.out.println("value: " + value);
		}
	}
	
	
	
	
	
	
	
	
	
	
}
